package com.cloudsigns.factorymanager2.engineering.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringDailyFeedBackBean;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringInstallationOrderBean;
import com.cloudsigns.factorymanager2.engineering.bean.OrderParentBean;
import com.cloudsigns.factorymanager2.engineering.presenter.EngineeringInstallOrderDetailPresenter;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;
import com.cloudsigns.factorymanager2.project.utils.DateUtil;

import org.json.JSONArray;
import org.json.JSONException;

import java.util.List;

public class EngineeringInstallDailyFeedBackDetailActivity extends Activity implements View.OnClickListener {
    private RelativeLayout rl_back;
    private TextView tv_title;
    private EngineeringDailyFeedBackBean engineeringDailyFeedBackBean;
    private TextView edt_feed_back_type, edt_unusual_reason, edt_advice, edt_impact, edt_feedback_people_colon, edt_feed_back_time, edt_confirm_person, edt_confirm_time;
    //edt_construct_content,
    private ImageView img1, img_add_1;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
            );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_daily_feedback_detail_for_engineering_install);


        init();
        Intent mIntent = getIntent();
        if (null != mIntent) {
            engineeringDailyFeedBackBean = (EngineeringDailyFeedBackBean) mIntent.getSerializableExtra(ConstantUtil.KEY_1);

            initData();
        }


    }

    private void init() {
        rl_back = findViewById(R.id.rl_back);
        tv_title = findViewById(R.id.tv_title);
//        edt_construct_content = findViewById(R.id.edt_construct_content);
        edt_feed_back_type = findViewById(R.id.edt_feed_back_type);
        edt_unusual_reason = findViewById(R.id.edt_unusual_reason);
        edt_advice = findViewById(R.id.edt_advice);
        edt_impact = findViewById(R.id.edt_impact);
        edt_feedback_people_colon = findViewById(R.id.edt_feedback_people_colon);
        edt_feed_back_time = findViewById(R.id.edt_feed_back_time);
        edt_confirm_person = findViewById(R.id.edt_confirm_person);
        edt_confirm_time = findViewById(R.id.edt_confirm_time);
        img1 = findViewById(R.id.img1);
        img_add_1 = findViewById(R.id.img_add_1);

        tv_title.setText(getResources().getText(R.string.daily_feed_back));


        rl_back.setOnClickListener(this);
    }

    private void initData() {
        if (null != engineeringDailyFeedBackBean) {

            CommonEnum.FeedBackType type = engineeringDailyFeedBackBean.getType();
            if (null != type) {
                if (type == CommonEnum.FeedBackType.NORMAL) {
                    edt_feed_back_type.setText("正常反馈");

                    String desc = engineeringDailyFeedBackBean.getContentDesc();
                    if (null != desc && !TextUtils.isEmpty(desc) && !"null".equals(desc))
                        edt_unusual_reason.setText(engineeringDailyFeedBackBean.getContentDesc());

                    String status = engineeringDailyFeedBackBean.getStatus();
                    if (null != status && !TextUtils.isEmpty(status) && !"null".equals(status))
                        edt_unusual_reason.setText(engineeringDailyFeedBackBean.getStatus());
                } else if (type == CommonEnum.FeedBackType.UNUSUAL) {
//                   T edt_feed_back_type.setText("异常反馈");

                    CommonEnum.SubType subype = engineeringDailyFeedBackBean.getSubType();
                    if (null != type) {
                        if (subype == CommonEnum.SubType.DAMAGE) {
                            edt_feed_back_type.setText("物流货损");
                        } else if (subype == CommonEnum.SubType.DELAY) {
                            edt_feed_back_type.setText("物流延误");
                        } else if (subype == CommonEnum.SubType.INSTALL_UNUSUAL) {
                            edt_feed_back_type.setText("安装异常");
                        } else if (subype == CommonEnum.SubType.OMIT) {
                            edt_feed_back_type.setText("物流漏货");
                        }
                    }

                    String reason = engineeringDailyFeedBackBean.getUnusualReason();
                    if (null != reason && !TextUtils.isEmpty(reason) && !"null".equals(reason))
                        edt_unusual_reason.setText(engineeringDailyFeedBackBean.getUnusualReason());


                } else if (type == CommonEnum.FeedBackType.COMPLETED) {
                    edt_feed_back_type.setText("完工反馈");
                }

            }

            String advice = engineeringDailyFeedBackBean.getAdvice();
            if (null != advice && !TextUtils.isEmpty(advice) && !"null".equals(advice))
                edt_advice.setText(engineeringDailyFeedBackBean.getAdvice());

            if (engineeringDailyFeedBackBean.getUnusualDays() > 0)
                edt_impact.setText(engineeringDailyFeedBackBean.getUnusualDays() + "天");

            List<String> imgUrlList = engineeringDailyFeedBackBean.getImgUrlList();
            if (null != imgUrlList) {
                for (int i = 0; i < imgUrlList.size(); i++) {
                    String urlStr = imgUrlList.get(i).toString().trim();
                    urlStr = urlStr.replace("[", "");
                    urlStr = urlStr.replace("]", "");
                    Uri uri = Uri.parse(urlStr);

                    Glide.with(this).load(uri).asBitmap().into(img1);
                    img_add_1.setVisibility(View.GONE);
                }
            }


            edt_feedback_people_colon.setText(engineeringDailyFeedBackBean.getAccountName());
            edt_feed_back_time.setText(DateUtil.getYyyy_Mm_Dd(engineeringDailyFeedBackBean.getFeedbackDate()));
            String accountid = engineeringDailyFeedBackBean.getHandlerAccountId();
            if (null != accountid && !TextUtils.isEmpty(accountid) && !"null".equals(accountid)) {
                edt_confirm_person.setText(engineeringDailyFeedBackBean.getHandlerAccountName());
            }

            edt_confirm_time.setText(DateUtil.getYyyy_Mm_Dd(engineeringDailyFeedBackBean.getHandleDate()));
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_back:
                finish();
                break;
        }

    }
}
